package com.rjxy.plansystemmanagement.utils;

import java.security.SecureRandom;
import java.util.Base64;

public class CouponCodeGenerator {

    private static final String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    private static final int CODE_LENGTH = 8; // 可以根据需要调整长度
    private static final SecureRandom random = new SecureRandom();

    /**
     * 生成一个优惠券兑换码
     *
     * @return 优惠券兑换码
     */
    public static String generateCouponCode() {
        StringBuilder couponCode = new StringBuilder(CODE_LENGTH);
        for (int i = 0; i < CODE_LENGTH; i++) {
            couponCode.append(CHARACTERS.charAt(random.nextInt(CHARACTERS.length())));
        }
        return couponCode.toString();
    }

    /**
     * 生成指定数量的优惠券兑换码
     *
     * @param quantity 需要生成的优惠券数量
     * @return 优惠券兑换码列表
     */
    public static String[] generateCouponCodes(int quantity) {
        String[] couponCodes = new String[quantity];
        for (int i = 0; i < quantity; i++) {
            couponCodes[i] = generateCouponCode();
        }
        return couponCodes;
    }

    public static void main(String[] args) {
        // 测试生成一个兑换码
        System.out.println("单个优惠券兑换码: " + generateCouponCode());

        // 测试生成多个兑换码
        String[] codes = generateCouponCodes(5);
        System.out.println("多个优惠券兑换码: ");
        for (String code : codes) {
            System.out.println(code);
        }
    }
}
